// 消息

import request, { singleRequest } from '@/utils/request'
import api from '@/utils/api'
import Cookies from 'js-cookie'

// 查询消息列表
export const queryMessageList = async (data = {}) => {
    const res = await singleRequest({
        url: '/message/list',
        method: 'post',
        data,
    })
    return res
}

// 新建消息
export const addNewMessage = async (data = {}) => {
    const res = await request({
        url: '/message/insert',
        method: 'post',
        data,
    })
    return res
}
// 编辑消息
export const editMessage = async (data = {}) => {
    const res = await request({
        url: '/message/edit',
        method: 'post',
        data,
    })
    return res
}
// 删除消息
export const delOneMessage = async (id) => {
    const res = await request({
        url: `/message/delete/${id}`,
        method: 'delete',
    })
    return res
}
// 获取创建人下拉框内容
export const getMessageCreateBy = async (params = {}) => {
    const res = await request({
        url: '/message/getCreateBy',
        method: 'get',
        params,
    })
    return res
}
// 发布消息
export const publicMessage = async (params = {}) => {
    const res = await request({
        url: '/message/publish',
        method: 'get',
        params,
    })
    return res
}
// 点击编辑回显消息信息
export const getMessageDetail = async (params = {}) => {
    const res = await request({
        url: '/message/editEcho',
        method: 'get',
        params,
    })
    return res
}
export const getTabAuth = async () => {
    let prefix = process.env.VUE_APP_UPLOAD_PREFIX || ''
    let response = await fetch(`//${prefix}manage.hgj.net/unified/api/app/menus?appKey=aides_admin&sessionId=${Cookies.get('manager_session_id')}`)
    let responseJson = await response.json()
    return responseJson
}

export const uploadFileNas = async (file, fileSuffix, fileName) => {
    let prefix = process.env.VUE_APP_UPLOAD_PREFIX || ''
    // let baseURL =
    //     prefix == 'dev-'
    //         ? `//iter-apisix.hgj.com/whale-nas-manager-server`
    //         : `//${prefix}file-ingress.hgj.com/whale-nas-manager-server`
    let baseURL = `${prefix}nas.hgj.com`
    const data = new FormData()
    data.append('multipartFile', file)
    data.append('type', 'aides-admin')
    data.append('relevanceId', file?.uid || new Date().getTime())
    data.append('downloadFileName', `${fileName}.${fileSuffix}`)
    const res = await api({
        headers: {
            appName: 'whale_common_pc',
        },
        baseURL,
        // url: '/access/upload/security/v1',
        url: '/upload/security/v1',
        method: 'post',
        data,
    })
    return res.data
}
